package rise.net;

import rise.message.Message;
import rise.message.Packet;
import android.content.Context;
import android.widget.Toast;

public class MessageTask extends SenderTask{

	public MessageTask(Message message, Context context) {
		super(message, context);
	}

	@Override
	protected Integer doInBackground(Void... params) {
		return super.doInBackground(params);
	}

	@Override
	protected void onPostExecute(Integer result) {
		if (result == Packet.CONNECTION_ERROR
				|| result == Packet.UNKNOWN_PACKET) {
			super.onPostExecute(result);
			return;
		}

		if (result == Message.OFFLINE_RECEIVER) {
			this.handleOfflineReceiver();
			return;
		}
		if (result == Packet.OK) {
			this.handleMessageSent();
			return;
		}
	}

	private void handleOfflineReceiver() {
		Toast toast = Toast.makeText(getContext(), "Il destinatario è offline, riceverà il messaggio al prossimo login.",
				Toast.LENGTH_SHORT);
		toast.show();
	}
	
	private void handleMessageSent(){
		Toast toast = Toast.makeText(getContext(), "Messaggio inviato.",
				Toast.LENGTH_SHORT);
		toast.show();		
	}

}
